<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/common/common.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>"> 
    <title>治疗费用界面</title>  
    <link rel="stylesheet" href="<%=path %>/plugins/layui/css/layui.css" media="all">
  </head>

  <script src="<%=path %>/plugins/layui/layui.js"></script>
  
  <body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
  <legend>新增治疗费用记录</legend>
</fieldset>
	<div class="layui-row">
	    <div class="layui-col-md12">
	      <div class="layui-row grid-demo">
	        <div class="layui-col-md9 layui-col-md-offset3">
	          <div class="grid-demo grid-demo-bg1">
	            <form class="layui-form layui-form-pane" id="recipeForm" lay-filter="example" action="">
	            
					<div class="layui-form-item">
				    	<label class="layui-form-label">患者信息</label>
					    <div class="layui-input-inline">
					      <select name="regId" lay-verify="required" id="stuSelect" lay-search lay-filter="stuSelect">
					      	<option value="1">请直接选择或搜索</option>
						  </select>
					    </div>
				    </div>
				   <div class="layui-form-item">
				    	<label class="layui-form-label">操作人</label>
				    	<div class="layui-input-inline">
				      		<input type="text" name="userName" readonly="readonly" lay-verify="userName" placeholder="请输入" autocomplete="off" class="layui-input">
				   		</div>
				   </div>
				  <div class="layui-row">
					 <div class="layui-col-md12">
					     <div class="layui-row grid-demo">
					        <div class="layui-col-md5">
					          	<div class="layui-form-item">
								    <label class="layui-form-label">治疗项目</label>
								    <div class="layui-input-inline">
										<input type="hidden" name="standFeeDesc" id="standList">
							        	<textarea readonly="readonly" id="standName" placeholder="请选择费用名称" lay-verify="required" class="layui-textarea"></textarea>
									</div>
									
								</div>
					        </div>
					        
					        <div class="layui-col-md7">
				        		<div class="layui-input-inline">
								  <input type="button" id="select" value="选择" class="layui-btn layui-btn-warm"/> 
							    </div>
					        </div>
					     </div>
					  </div>
				  </div>
					        
				  <div class="layui-form-item" style="margin-left: 150px;margin-top: 80px">
				   <!-- 这行很奇怪啊 为什么会跳到/biz/Recipe_openAdd.action -->
				   <!-- <button class="layui-btn" lay-submit="" lay-filter="submits">保存信息 </button> --> 
				   <input type="button" class="layui-btn" lay-submit="" lay-filter="submit" value="保存信息">
				  </div>
				  <!-- 瘾君子 -->
				  
				   
				</form>  
	          </div>
	        </div>
	        

	      </div>
	    </div>
	 </div>


</body>
  
<script>
layui.use(['form', 'layedit', 'laydate', 'layer', 'jquery'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,laydate = layui.laydate
  ,$ = layui.jquery;
  stuSelect();
  
  //初始化下拉列表
  function stuSelect(){
  	var d = $("#stuSelect");
  	$.ajax({
	           url : '<%=path%>/biz/StandFee_getAllStu.action',
	           type:'get',
	           dataType: 'json',
	           success:function(data){
				   layui.each(data, function(index, item){
				   		$("#stuSelect").append("<option value="+item.regId+">"+item.regId+" "+item.stuName+"</option>");
				   }); 	               
	               form.render('select');
	           },
	           error : function() {
	               layer.alert("请求异常！");
	           }
          })
  }
  
  //监听患者选择select
  form.on('select(stuSelect)', function(data){
		
  });
  
  //监听提交
  form.on('submit(submit)', function(data){
  	var state = $("#stuSelect").val();
  	if(state == 1){
  		layer.msg("请选择患者信息");
  		return false;
  	}
	$.ajax({
		url: '<%=path%>/biz/StandFee_add.action',
		type: 'POST',
		data: $('#recipeForm').serialize(),
		dataType: 'json',
		success: function(data){
			var json = eval("("+data+")");
			//添加成功
			if(json.isSucceed){
			      layer.open({
			        content: '<div style="padding: 20px 100px;">添加成功</div>'
			        ,btn: '朕知道啦'
			        ,btnAlign: 'c' //按钮居中
			        ,shade: 0 //不显示遮罩
			        ,yes: function(){
						//返回列表
						location.href = "<%=path%>/biz/StandFee_standFeeList.action";
			        }
			      });
			}else{
				message("添加失败~不解释");
				//关闭当前iframe弹出层
				parent.layer.close();
			}
		},
		error: function(data){
			layer.msg("请求失败");
		}
	});	
    return false;//阻止表单跳转
  });  
  
  //表单初始赋值
  form.val('example', {
    "userName": '${user.userName}'
  });
  
  //信息提示弹出层
  function message(data){
      layer.open({
        content: '<div style="padding: 20px 100px;">'+ data +'</div>'
        ,btn: '朕知道啦'
        ,btnAlign: 'c' //按钮居中
        ,shade: 0 //不显示遮罩
        ,yes: function(){
          layer.closeAll();
        }
      });
  };
  
    $('#select').on('click', function(){
 	//打开药品选择页面
	layer.open({
	  type: 2,
	  area: ['85%', '92%'],
	  fixed: false,    //弹框位置不固定
	  maxmin: true,
	  content: '<%=path%>/biz/Standard_openChoice.action',
	  btn: ['确定保存','取消'],
	  btnAlign: 'c', //按钮剧中
	  anim: 0, //平滑放大
	  yes: function(index, layero){
	    //获取iframe的body元素  
	    var body = layer.getChildFrame('body',index);  
	    //得到iframe页的窗口对象  
	    var iframeWin = window[layero.find('iframe')[0]['name']];                 
	    //执行iframe页的方法，接收药箱  
	    var data = iframeWin.messages();
	    //循环药箱
	    $.each(data, function(key, val) {
		    console.log('id:' + key + ", med:" + val.standName);
		    //获取原先的药品
		    var standName = $("#standName").val();
		    //药品累加(\n为换行符)
		    $("#standName").val(standName+val.standName+" "+val.count+"次\n");
		    //用于返回给后台(a,b为分隔符)
		    var standList = $("#standList").val()
		    $("#standList").val(standList+val.standId+"a"+val.count+"b");
		    // 如果想退出循环
		    // return false;
		});
		layer.close(index);
	  },
	  success: function(layero, index){
	  	//再打开药箱则清空已选药品(待完善:不清空,根据已选药品在打开的药箱中显示出来)
	  	$("#standName").val("");
	  	$("#standLists").val("");
	  },
	  btn2: function(index){
	  	layer.close(index);
	  }
	});
  });
  
  $('#layerDemo .layui-btn').on('click', function(){
    var othis = $(this), method = othis.data('method');
    active[method] ? active[method].call(this, othis) : '';
  });
  
});

</script>
<script>

</script>
</html>
